//
//  CustomTableViewCell.m
//  PLRLiveShow
//
//  Created by 赵小燕 on 2017/8/20.
//  Copyright © 2017年 xiaoyanzhao. All rights reserved.
//

#import "CustomTableViewCell.h"
#import <Masonry.h>

@interface CustomTableViewCell ()

@property (nonatomic, strong) UIImageView *smallImageView;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *rightLabel;

@end

@implementation CustomTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.smallImageView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10, 20, 20)];
//        self.smallImageView.backgroundColor = [UIColor redColor];
//        [self.contentView addSubview:self.smallImageView];
//        
//        self.label = [[UILabel alloc] initWithFrame:CGRectMake(48, 12, 0, 0)];
//        self.label.font = [UIFont systemFontOfSize:12];
//        [self.contentView addSubview:self.label];
//        
//        self.rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(330, 15, 0, 0)];
//        self.rightLabel.font = [UIFont systemFontOfSize:9];
//        [self.contentView addSubview:self.rightLabel];
//        
//        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        _smallImageView = [UIImageView new];
        _smallImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_smallImageView];
        
        [_smallImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 20));
            make.centerY.equalTo(self);
            make.left.mas_offset(16);
        }];
        
        _label = [UILabel new];
        _label.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_label];
        
        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_smallImageView);
            // 添加约束（这里的间距是有方向性的，左、上边距约束为正数，右、下边距约束为负数）
            make.left.equalTo(_smallImageView.mas_right).offset(12);
        }];
        
        _rightLabel = [UILabel new];
        _rightLabel.font = [UIFont systemFontOfSize:9];
        [self.contentView addSubview:_rightLabel];
        
        [_rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self.mas_right).offset(-30);
        }];
    }
    return self;
}

- (void)setDataModel:(CellDataModel *)dataModel {
    _dataModel = dataModel;
    self.label.text = _dataModel.leftTitle;
    [self.label sizeToFit];
    
    self.rightLabel.text = _dataModel.rightTitle;
    [self.rightLabel sizeToFit];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];    
    // Configure the view for the selected state
}

@end
